package com.project.fortuneteller.utils;
import java.util.Random;
// DayanMethodUtil类用于模拟大衍筮法的步骤
public class DayanMethodUtil {

    // 模拟大衍筮法计算一个爻
    public static String calculateYao() {
        int totalSticks = 49; // 初始49根蓍草
        int yaoValue = 0;

        for (int i = 0; i < 3; i++) { // 三次步骤
            totalSticks -= 1; // 去掉一根蓍草
            int left = (new Random()).nextInt(totalSticks ) + 1; // 左边分一堆
            int right = totalSticks - left; // 右边为另一堆
            int modLeft = left % 4;
            int modRight = right % 4;
            if (modLeft == 0) modLeft = 4; // 若为0则为4
            if (modRight == 0) modRight = 4;
            yaoValue += (modLeft + modRight); // 累加模4的结果
            totalSticks = left + right - (modLeft + modRight); // 重新计算剩余蓍草数
        }
         int n =  totalSticks/4;
//        System.out.print();
        // 根据爻的值确定阴阳爻  剩余蓍草数量

        return Integer.toString(n);


    }
}